<template>
  <!-- 我的钱包页面 -->
  <view class="main">
    <view class="wallet">
      <text class="text">钱包余额</text>
      <view class="num">
        ￥<text>{{ money }}</text>
      </view>
    </view>
    <view class="nav">
      <navigator
        url="/pages/per_center/transactionRecords"
        hover-class="none"
        class="trading"
      >
        <text>交易记录</text>
        <image src="../../imges/you.png" mode="aspectFill"></image>
      </navigator>
      <navigator
        url="/pages/per_center/exceptionalRecord"
        hover-class="none"
        class="exceptional"
      >
        <text>打赏记录</text>
        <image src="../../imges/you.png" mode="aspectFill"></image>
      </navigator>
      <!--<navigator url="/pages/per_center/communityBenefits" hover-class="none" class="exceptional">
				<text>圈子收益</text>
				<image src="../../imges/you.png" mode="aspectFill"></image>
			</navigator> -->

      <view class="exceptional" @tap="handleTiao" v-if="openApp.phone == 'ios'">
        <text>圈子收益</text>
        <image src="../../imges/you.png" mode="aspectFill"></image>
      </view>

      <view
        class="wxOpenInAPP"
        v-if="openApp.iswx == 'wx' && openApp.phone == 'Android'"
      >
        <view class="text_go">
          <wx-open-launch-app
            id="launch-btn"
            appid="wx8737e94836340f56"
            @error="openApp.handleErrorFn"
            @launch="openApp.handleLaunchFn"
            :extinfo="extinfoid"
          >
            <script type="text/wxtag-template">
                      <style>
                        .btn {
                 	      color: #424242;
                          font-size: 16px;
                          display: inline-block;
              width: 260px;
                        }
                      </style>
                      <view class="btn">圈子收益</view>
            </script>
          </wx-open-launch-app>
        </view>
        <image src="../../imges/you.png" mode="aspectFill"></image>
      </view>
    </view>
  </view>
</template>

<script>
import "../../utils/toApp.js";
import request from "../../utils/request.js";
let jweixin = require("jweixin-module"); //引入配置
export default {
  data() {
    return {
      money: "",
      extinfoid: "", //url
    };
  },
  onLoad(option) {
    this.money = option.yue;
  },
  onShow() {
    this.configWeiXin();
  },
  methods: {
    configWeiXin() {
      //获取公众号配置
      request({
        //获取appid
        url: "wechat/portal/jsapiSignature/",
        method: "POST",
        header: {
          "Content-Type": "application/json",
          "api-client": "72e0fee8172411ea995200163e05ff66",
          "api-version": "1.3.3",
          "Source-Type": 7,
        },
        data: {
          url: window.location.href.split("#")[0], //后台通过域名进行授权
        },
      }).then((res) => {
        if (res.statusCode == 200) {
          //获取成功
          jweixin.config({
            debug: false, // 开启调试模式，发布的时候改为false
            appId: res.data.appId, // 必填，公众号的唯一标识
            timestamp: res.data.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
            signature: res.data.signature, // 必填，签名
            jsApiList: ["updateAppMessageShareData", "updateTimelineShareData"], // 必填，需要使用的JS接口列表
            openTagList: ["wx-open-launch-app"],
          });
          jweixin.ready(function () {});
        } else {
          uni.showToast({
            title: res.data.msg,
            duration: 2000,
            icon: "none",
          });
        }
      });

      if (this.openApp.iswx == "wx" && this.openApp.phone == "Android") {
        this.extinfoid = `yqlw://yilaiwang.com/openDetail?jumpType=12&serviceId=''&type=1&orgId=''&content=''`;
      }
    },
    handleTiao() {
      uni.showModal({
        title: "前往APP",
        content: "即将离开微信，打开“一起来往”查看我的圈子收益",
        confirmText: "允许",
        success: (res) => {
          if (res.confirm) {
            uni.showLoading({
              title: "加载中，请稍等~",
            });
            setTimeout(function () {
              uni.hideLoading();
            }, 3000);
            var url = window.location.href.split("&code")[0];
            window.history.pushState({}, 0, url);
            this.openApp.toApps(12, "", 1, "", "");
          }
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.wallet {
  width: 100%;
  height: 400rpx;
  background-color: #2168eb;
  color: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;

  .text {
    width: 200rpx;
    text-align: center;
    position: absolute;
    left: 275rpx;
    top: 100rpx;
    font-size: 32rpx;
  }

  .num {
    font-size: 32rpx;

    text {
      font-size: 80rpx;
    }
  }
}

.nav {
  padding: 0 34rpx;
  box-sizing: border-box;

  .trading,
  .exceptional {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    color: #333333;
    padding: 45rpx 0;
    border-bottom: 1rpx solid #dddddd;

    image {
      width: 26rpx;
      height: 32rpx;
    }
  }
  .wxOpenInAPP {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    color: #333333;
    padding: 45rpx 0;
    border-bottom: 1rpx solid #dddddd;

    image {
      width: 26rpx;
      height: 32rpx;
    }
  }
}
</style>
